﻿using CloudMusic.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudMusic.Helper
{
    public class EntityHelper
    {
        public static MusicModel SetMusicModel(SongsItem songs,PrivilegesItem privilegesItems,long id,string songName,int i)
        {
            MusicModel mm = new MusicModel
            {
                Index = i < 9 ? "0" + (i + 1).ToString() : i.ToString(),
                Album = songs.al.name,
                AlbumId = songs.al.id,
                Name = CommonHelper.GetTitle(songs.name, songs.alia),
                Id = songs.id,
                CoverTitle = CommonHelper.GetTitle(songs.name, songs.alia),
                Artist = songs.ar[0].name,
                SingerId = songs.ar[0].id,
                Type = 1,
                PicUrl = songs.al.picUrl,
                SongId = id,
                CanPlay = true,
                TimeStr = DateTimeHelper.GetTime((songs.dt / 1000).ToString()),
                MVVis = CommonHelper.GetMvVis(songs.mv),
                VIPVis = CommonHelper.GetVis(privilegesItems.fee),
                STVis = CommonHelper.GetVis(privilegesItems.fee),
                SQVis = CommonHelper.GetVis(privilegesItems.maxbr),
                Source = songName,
                ChargeInfoList = GetChargeInfos(privilegesItems.chargeInfoList)
            };

            return mm;
        }
        public static List<ChargeInfo> GetChargeInfos(List<ChargeInfoList> ch)
        {
            List<ChargeInfo> chargeInfos = new List<ChargeInfo>();
            for (int i = 0; i < ch.Count; i++)
            {
                chargeInfos.Add(new ChargeInfo
                {
                    Rate = ch[i].rate,
                    ChargeMessage = ch[i].chargeMessage,
                    chargeType = ch[i].chargeType,
                    chargeUrl = ch[i].chargeUrl
                });
            }
            return chargeInfos;
        }
    }
}
